package com.explorati.LeetCode078.subsets;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 19:13 2020/10/5 0005
 * @ Description ：
 */
public class Solution {

    /**
     * 给定一组不含重复元素的整数数组 nums，返回该数组所有可能的子集（幂集）。
     * @param nums
     * @return
     */
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {

        Deque<Integer> preList = new ArrayDeque();
        generateSubsets(nums, 0, preList);

        return res;
    }

    private void generateSubsets(int[] nums, int index, Deque preList) {
        res.add(new ArrayList<>(preList));

        for(int i = index; i < nums.length; i++) {
            preList.add(nums[i]);
            generateSubsets(nums, i + 1, preList);
            preList.removeLast();
        }
    }
}
